home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.06 Jun 88 / serial demo / HandleChars.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-04-24  |  2.3 KB  |  96 lines  |  [TEXT/PJMM]

  1. UNIT HandleChars;
  2.  
  3. INTERFACE
  4.  
  5.     USES
  6.         Globals, GPLib;
  7.  
  8.     PROCEDURE DisplayChar (charread : char);
  9.     PROCEDURE Put_Char (tempchar : integer;
  10.                                     CharRead : Char);
  11.     PROCEDURE Handle_keys (keyPressed : Char);
  12.     PROCEDURE Get_comm_input;
  13.  
  14. IMPLEMENTATION
  15.  
  16.     PROCEDURE DisplayChar;                 {(charread : char)}
  17.     BEGIN
  18.         gotoxy(column, row);
  19.         drawchar(charread);
  20.         column := column + 1;
  21.     END;
  22.  
  23.     PROCEDURE Put_Char;            { (tempchar : integer;CharRead : Char)}
  24.  
  25.     BEGIN
  26.         CASE tempchar OF
  27.             CrRtn, LineFeed : 
  28.                 BEGIN
  29.                     IF row <= windowlines THEN
  30.                         row := row + 1
  31.                     ELSE
  32.                         BEGIN
  33.                             ScrollRect(thePort^.portRect, 0, -12, Urgn);
  34.                         END;
  35.                     Column := 1;
  36.                     gotoxy(column, row);
  37.                 END;
  38.             OTHERWISE
  39.                 DisplayChar(CharRead);
  40.         END;            {tempchar}
  41.     END;
  42.  
  43. {------------ handle all keyDown events, including command-keys --------------}
  44.     PROCEDURE Handle_keys;                {(keyPressed : Char)}
  45.  
  46.         VAR
  47.             oneChar : LongInt;
  48.             charAddr : Ptr;
  49.  
  50.     BEGIN
  51.         onechar := 1;
  52.         charAddr := POINTER(1 + ORD4(@keyPressed));   {char in low-order byte of word}
  53.  
  54.         err := FSWrite(outRefNum, oneChar, charAddr);   {send out serial port}
  55.     END;      {Handle_keys}
  56.  
  57.  
  58.                 { get the next character from the input buffer currently selected }
  59.  
  60.     PROCEDURE GetChar (VAR xchar : char);
  61.         VAR
  62.             errorCode : Integer;
  63.  
  64.     BEGIN
  65.         errorCode := FSRead(inRefNum, oneCount, filterBuffPtr);
  66.         Xchar := Chr(filterBuffPtr^);    { get the character pointed to by filterBuffPtr }
  67.         BitClr(@XChar, 8);                {clear the high bit for ascii data, not used for binary data}
  68.     END;
  69.  
  70. {-------------------get characters from serial port, and filter ---------------}
  71.  
  72.     PROCEDURE Get_comm_input;
  73.  
  74.         VAR
  75.             errorCode, tempchar : INTEGER;
  76.             inCount : LongInt;
  77.  
  78.     BEGIN
  79.         errorCode := SerGetBuf(inRefNum, inCount);      {get # of char in input buffer}
  80.  
  81. (* ------- use the code below to very SLOWLY strip line feed characters --------- *)
  82.         IF inCount > 0 THEN
  83.             BEGIN
  84.                 GetChar(Charread);
  85.                 IF ord(charRead) <> 0 THEN
  86.                     BEGIN
  87.                         tempchar := BitAnd(ord(charRead), 127);        { clear the high bit }
  88.                         IF (portA) THEN
  89.                             setport(windowB)       { we are writing out port A, we are reading port B }
  90.                         ELSE
  91.                             setport(windowA);       { we are writing out port B, we are reading port A }
  92.                         Put_Char(tempchar, charRead)
  93.                     END;                    {if charRead}
  94.             END;                        {if incount}
  95.     END;                            {Get_Comm_input}
  96. END.